package com.web;

import com.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 员工删除客户的活动数据
 * 接收userShowAct.jsp页面的userId、activityId数据，
 * 提交到userService的deleteUserAct函数
 * 重定向到/ShowUserAct
 */
@WebServlet("/DeleteUserAct")
public class DeleteUserActServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.解决乱码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //2.接收参数
        String userId = request.getParameter("userId");
        String activityId = request.getParameter("activityId");

        System.out.println("正在删除userId= "+userId +"activityId= "+activityId +"的数据");
        //3.调用service层的 进行删除
        new userService().deleteUserAct(Integer.parseInt(userId),Integer.parseInt(activityId));
        //4.重定向到查询客户的活动,带上userId
        response.sendRedirect(request.getContextPath()+"/ShowUserAct?userId="+userId);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
